//TO-Do: invalidate DO it when nothing is done.
//somehow, the when try to build the house again, there are one more house for each prop.

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

//After pressing BUILD button, this dialog box will appear.
/*Build Dialog does
 *  - display the properties on which the player can build Houses/hotels if the player completed the color
 *  - show the houses/hotels based on the already-owned houses/hotels. 
 *  - build the buildings by clicking on the buttons(houses images).
 *  - the dialog keeps track of the resulting amount of cash and how much we have to pay
 *  - the amount of money to be payed mustn't exceed the current cash(in this case, the player cant press confirm button.
 *  - after confirming, the player can update the property list and current cash and SOMETHING MORE???
 */

class BuildDialog extends JDialog implements ActionListener {
	JButton doIt, cancel;
	JPanel panel;
	double startingCash;
	IntContainer totalCost;
	static int remainingCash;
	Player currentPlayer;
	private int returnValue;
	JOptionPane noPropComplete;

	
	IntContainer NumHouseDarkPurple1, NumHouseDarkPurple2, NumHouseLightBlue1,
			NumHouseLightBlue2, NumHouseLightBlue3, NumHouseLightPurple1,
			NumHouseLightPurple2, NumHouseLightPurple3, NumHouseOrange1,
			NumHouseOrange2, NumHouseOrange3, NumHouseRed1, NumHouseRed2,
			NumHouseRed3, NumHouseYellow1, NumHouseYellow2, NumHouseYellow3,
			NumHouseGreen1, NumHouseGreen2, NumHouseGreen3, NumHouseDarkBlue1,
			NumHouseDarkBlue2;

	BooleanContainer hasHotelDarkPurple1, hasHotelDarkPurple2,
			hasHotelLightBlue1, hasHotelLightBlue2, hasHotelLightBlue3,
			hasHotelLightPurple1, hasHotelLightPurple2, hasHotelLightPurple3,
			hasHotelOrange1, hasHotelOrange2, hasHotelOrange3, hasHotelRed1,
			hasHotelRed2, hasHotelRed3, hasHotelYellow1, hasHotelYellow2,
			hasHotelYellow3, hasHotelGreen1, hasHotelGreen2, hasHotelGreen3,
			hasHotelDarkBlue1, hasHotelDarkBlue2;

	// VARIABLES FOR TESTING
	// Player currentPlayer;

	BuildDialog(Player p) {
		this.currentPlayer = p;
		// TEST PART
		/*
		currentPlayer = new Player();
		currentPlayer.setPlayerName("Takahiro");
		*/
		/*
		  currentPlayer.addNewProperty("MediterraneanAve");
		  currentPlayer.addNewProperty("BalticAve");
		  this.currentPlayer.buildHouse("MediterraneanAve",4); 
		  this.currentPlayer.buildHouse("BalticAve", 4);
		  this.currentPlayer.buildHotel("MediterraneanAve");
		  /*
		  this.currentPlayer.addNewProperty("NewYorkAve");
		  this.currentPlayer.addNewProperty("TennesseeAve");
		  this.currentPlayer.addNewProperty("StJamesPlace");
		  this.currentPlayer.buildHouse("NewYorkAve", 0);
		  this.currentPlayer.buildHouse("TennesseeAve", 1);
		  this.currentPlayer.buildHouse("StJamesPlace", 0);
		  
		  this.currentPlayer.addNewProperty("OrientalAve");
		  this.currentPlayer.addNewProperty("VermontAve");
		  this.currentPlayer.addNewProperty("ConnecticutAve");
		  this.currentPlayer.buildHouse("OrientalAve", 0);
		  this.currentPlayer.buildHouse("VermontAve", 1);
		  this.currentPlayer.buildHouse("ConnecticutAve", 0);
		  
		  
		  this.currentPlayer.addNewProperty("PacificAve");
		  this.currentPlayer.addNewProperty("NorthCarolinaAve");
		  this.currentPlayer.addNewProperty("PennsylvaniaAve");
		  this.currentPlayer.buildHouse("PacificAve", 0);
		  this.currentPlayer.buildHouse("NorthCarolinaAve", 0);
		  this.currentPlayer.buildHouse("PennsylvaniaAve", 0);
		  this.currentPlayer.mortgage("PacificAve");
		 */
		System.out.println("Initial total Wealth is " + this.currentPlayer.getTotalWealth());

		returnValue = -1;
		totalCost = new IntContainer(0);
		remainingCash = currentPlayer.getCash();
		JLabel totalCostLabel = new JLabel("Total cost: $"
				+ totalCost.intValue());
		JLabel remainingCashLabel = new JLabel("Cash remaining: $"
				+ remainingCash);

		System.out.println("totalHouse: " + currentPlayer.getTotalHouseNum());
		System.out.println("totalHotel: " + currentPlayer.getTotalHotelNum());
		this.setUndecorated(true);

		// possible buildings to be built. it's a test part
		// they're shown by using scroll bar
		// TEST PART: just to see how they looks
		JPanel availableProperties = new JPanel();
		availableProperties.setLayout(new GridLayout(0, 1));

		//check if the player can build houses/hotel.
		if(hasCompleteGroup() == false){
			JLabel warning = new JLabel(
					"You need to complete one of the property groups of the same color.");
			JOptionPane.showMessageDialog(this, warning);
			returnValue = 0;
			this.setVisible(false);
		}
		else if(canBuild() == false){//if some property group is complete and doesn't have mortgaged property,
			// the following code cannot be executed.
			
			
			JLabel warning = new JLabel(
					"To build houses/hotel on a property, every property of the same color should not be mortgaged.");
			JOptionPane.showMessageDialog(this, warning);
			returnValue = 0;
			this.setVisible(false);
		}//the following code is executed only if some property group is complete.
		else{
			// Now adding the ButtonPanel if the color is complete and no
			// property is not mortgaged.
			if (currentPlayer.isDarkPurpleComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer.getDarkPurpleNameAt(0)) == false&& 
						currentPlayer.isMortgaged(currentPlayer.getDarkPurpleNameAt(1)) == false) {
					NumHouseDarkPurple1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer.getDarkPurpleNameAt(0)));
					NumHouseDarkPurple2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer.getDarkPurpleNameAt(1)));
					this.hasHotelDarkPurple1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer.getDarkPurpleNameAt(0)));
					this.hasHotelDarkPurple2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer.getDarkPurpleNameAt(1)));
					int size = currentPlayer.getDarkPurpleSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getDarkPurpleNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseDarkPurple1,
								NumHouseDarkPurple2, new IntContainer(0),
								totalCostLabel, remainingCashLabel,
								hasHotelDarkPurple1, hasHotelDarkPurple2,
								new BooleanContainer(false)));
					}
				}
			}
			if (currentPlayer.isLightBlueComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer
						.getLightBlueNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getLightBlueNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getLightBlueNameAt(2)) == false) {
					NumHouseLightBlue1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightBlueNameAt(0)));
					NumHouseLightBlue2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightBlueNameAt(1)));
					NumHouseLightBlue3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightBlueNameAt(2)));

					this.hasHotelLightBlue1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightBlueNameAt(0)));
					this.hasHotelLightBlue2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightBlueNameAt(1)));
					this.hasHotelLightBlue3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightBlueNameAt(2)));
					int size = currentPlayer.getLightBlueSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getLightBlueNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseLightBlue1,
								NumHouseLightBlue2, NumHouseLightBlue3,
								totalCostLabel, remainingCashLabel,
								hasHotelLightBlue1, hasHotelLightBlue2,
								hasHotelLightBlue3));
					}
				}
			}
			if (currentPlayer.isLightPurpleComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer
						.getLightPurpleNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getLightPurpleNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getLightPurpleNameAt(2)) == false) {
					NumHouseLightPurple1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightPurpleNameAt(0)));
					NumHouseLightPurple2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightPurpleNameAt(1)));
					NumHouseLightPurple3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getLightPurpleNameAt(2)));
					this.hasHotelLightPurple1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightPurpleNameAt(0)));
					this.hasHotelLightPurple2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightPurpleNameAt(1)));
					this.hasHotelLightPurple3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getLightPurpleNameAt(2)));
					int size = currentPlayer.getLightPurpleSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getLightPurpleNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseLightPurple1,
								NumHouseLightPurple2, NumHouseLightPurple3,
								totalCostLabel, remainingCashLabel,
								hasHotelLightPurple1, hasHotelLightPurple2,
								hasHotelLightPurple3));
					}
				}
			}
			if (currentPlayer.isOrangeComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer.getOrangeNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getOrangeNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getOrangeNameAt(2)) == false) {
					NumHouseOrange1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getOrangeNameAt(0)));
					NumHouseOrange2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getOrangeNameAt(1)));
					NumHouseOrange3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getOrangeNameAt(2)));
					this.hasHotelOrange1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getOrangeNameAt(0)));
					this.hasHotelOrange2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getOrangeNameAt(1)));
					this.hasHotelOrange3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getOrangeNameAt(2)));

					int size = currentPlayer.getOrangeSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getOrangeNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseOrange1,
								NumHouseOrange2, NumHouseOrange3,
								totalCostLabel, remainingCashLabel,
								hasHotelOrange1, hasHotelOrange2,
								hasHotelOrange3));
					}
				}
			}
			if (currentPlayer.isRedComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer.getRedNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getRedNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getRedNameAt(2)) == false) {
					NumHouseRed1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getRedNameAt(0)));
					NumHouseRed2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getRedNameAt(1)));
					NumHouseRed3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getRedNameAt(2)));
					this.hasHotelRed1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getRedNameAt(0)));
					this.hasHotelRed2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getRedNameAt(1)));
					this.hasHotelRed3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getRedNameAt(2)));
					int size = currentPlayer.getRedSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getRedNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseRed1,
								NumHouseRed2, NumHouseRed3, totalCostLabel,
								remainingCashLabel, hasHotelRed1, hasHotelRed2,
								hasHotelRed3));
					}
				}
			}
			if (currentPlayer.isYellowComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer.getYellowNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getYellowNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getYellowNameAt(2)) == false) {
					NumHouseYellow1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getYellowNameAt(0)));
					NumHouseYellow2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getYellowNameAt(1)));
					NumHouseYellow3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getYellowNameAt(2)));
					this.hasHotelYellow1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getYellowNameAt(0)));
					this.hasHotelYellow2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getYellowNameAt(1)));
					this.hasHotelYellow3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getYellowNameAt(2)));
					int size = currentPlayer.getYellowSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getYellowNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseYellow1,
								NumHouseYellow2, NumHouseYellow3,
								totalCostLabel, remainingCashLabel,
								hasHotelYellow1, hasHotelYellow2,
								hasHotelYellow3));
					}
				}
			}
			if (currentPlayer.isGreenComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer.getGreenNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getGreenNameAt(1)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getGreenNameAt(2)) == false) {
					NumHouseGreen1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getGreenNameAt(0)));
					NumHouseGreen2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getGreenNameAt(1)));
					NumHouseGreen3 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getGreenNameAt(2)));
					this.hasHotelGreen1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getGreenNameAt(0)));
					this.hasHotelGreen2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getGreenNameAt(1)));
					this.hasHotelGreen3 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getGreenNameAt(2)));

					int size = currentPlayer.getGreenSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getGreenNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseGreen1,
								NumHouseGreen2, NumHouseGreen3, totalCostLabel,
								remainingCashLabel, hasHotelGreen1,
								hasHotelGreen2, hasHotelGreen3));
					}
				}
			}
			if (currentPlayer.isDarkBlueComplete()) {
				if (currentPlayer.isMortgaged(currentPlayer
						.getDarkBlueNameAt(0)) == false
						&& currentPlayer.isMortgaged(currentPlayer
								.getDarkBlueNameAt(1)) == false) {
					NumHouseDarkBlue1 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getDarkBlueNameAt(0)));
					NumHouseDarkBlue2 = new IntContainer(
							currentPlayer.getNumberOfHouses(currentPlayer
									.getDarkBlueNameAt(1)));
					this.hasHotelDarkBlue1 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getDarkBlueNameAt(0)));
					this.hasHotelDarkBlue2 = new BooleanContainer(
							currentPlayer.hasHotel(currentPlayer
									.getDarkBlueNameAt(1)));

					int size = currentPlayer.getDarkBlueSize();
					for (int i = 0; i < size; i++) {
						String name = currentPlayer.getDarkBlueNameAt(i);
						availableProperties.add(new ButtonsOfHouseHotel(
								currentPlayer, size, i, totalCost,
								remainingCash, name, currentPlayer
										.getNumberOfHouses(name), currentPlayer
										.hasHotel(name), NumHouseDarkBlue1,
								NumHouseDarkBlue2, new IntContainer(0),
								totalCostLabel, remainingCashLabel,
								hasHotelDarkBlue1, hasHotelDarkBlue2,
								new BooleanContainer(false)));
					}
				}
			}

			JScrollPane scroll = new JScrollPane(availableProperties,
					JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
					JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
			scroll.setPreferredSize(new Dimension(400, 200));

			// a panel that contains buttons, confirm or cancel
			JPanel panelWithButtons = new JPanel();
			doIt = new JButton("Do It!");
			cancel = new JButton("Cancel");
			panelWithButtons.add(doIt);
			panelWithButtons.add(cancel);
			doIt.addActionListener(this);
			cancel.addActionListener(this);

			// a panel put on the center of the border layout
			panel = new JPanel();
			panel.add(new JLabel("Click on the houses to build them"));
			panel.add(scroll);
			// show the result of the calculation
			JPanel showCashPanel = new JPanel();
			showCashPanel.setPreferredSize(new Dimension(300, 150));
			showCashPanel.setLayout(new GridLayout(4, 0));

			// showCashPanel.add(new JLabel("Starting cash: $" +
			// currentPlayer.getCash()));//TEST part
			showCashPanel.add(new JLabel("Starting cash: $"
					+ this.currentPlayer.getCash()));
			showCashPanel.add(totalCostLabel);
			showCashPanel.add(remainingCashLabel);
			showCashPanel.add(panelWithButtons);// defined above
			panel.add(showCashPanel);
			//panel.setBackground(Color.black);
			panel.setVisible(true);

			// putting them together
			setSize(450, 470);
			setModal(true);
			setLayout(new BorderLayout(0, 0));

			add(new JLabel(new ImageIcon("./menuButtons/buildHouseHotel.JPG")),
					BorderLayout.NORTH);
			add(panel, BorderLayout.CENTER);

			
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		}
	}
	

	public void updateBuildings(Player p) {
		if (p.isDarkPurpleComplete()) {
			p.buildHouse(
					p.getDarkPurpleNameAt(0),
					NumHouseDarkPurple1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getDarkPurpleNameAt(0)));
			p.buildHouse(
					p.getDarkPurpleNameAt(1),
					NumHouseDarkPurple2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getDarkPurpleNameAt(1)));
			if (hasHotelDarkPurple1.boolValue() == true)
				p.buildHotel(p.getDarkPurpleNameAt(0));
			else
				p.removeHotel(p.getDarkPurpleNameAt(0));
			if (hasHotelDarkPurple2.boolValue() == true)
				p.buildHotel(p.getDarkPurpleNameAt(1));
			else
				p.removeHotel(p.getDarkPurpleNameAt(1));
		}
		if (p.isLightBlueComplete()) {
			// build house
			System.out.println(NumHouseLightBlue1.intValue() - this.currentPlayer.getNumberOfHouses(this.currentPlayer							.getLightBlueNameAt(0)));// test
			p.buildHouse(
					p.getLightBlueNameAt(0),
					NumHouseLightBlue1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightBlueNameAt(0)));
			p.buildHouse(
					p.getLightBlueNameAt(1),
					NumHouseLightBlue2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightBlueNameAt(1)));
			p.buildHouse(
					p.getLightBlueNameAt(2),
					NumHouseLightBlue3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightBlueNameAt(2)));
			// build hotel
			if (hasHotelLightBlue1.boolValue() == true)
				p.buildHotel(p.getLightBlueNameAt(0));
			else
				p.removeHotel(p.getLightBlueNameAt(0));
			if (hasHotelLightBlue2.boolValue() == true)
				p.buildHotel(p.getLightBlueNameAt(1));
			else
				p.removeHotel(p.getLightBlueNameAt(1));
			if (hasHotelLightBlue3.boolValue() == true)
				p.buildHotel(p.getLightBlueNameAt(2));
			else
				p.removeHotel(p.getLightBlueNameAt(2));
		}
		if (p.isLightPurpleComplete()) {
			p.buildHouse(
					p.getLightPurpleNameAt(0),
					NumHouseLightPurple1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightPurpleNameAt(0)));
			p.buildHouse(
					p.getLightPurpleNameAt(1),
					NumHouseLightPurple2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightPurpleNameAt(1)));
			p.buildHouse(
					p.getLightPurpleNameAt(2),
					NumHouseLightPurple3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getLightPurpleNameAt(2)));
			// build hotel
			if (hasHotelLightPurple1.boolValue() == true)
				p.buildHotel(p.getLightPurpleNameAt(0));
			else
				p.removeHotel(p.getLightPurpleNameAt(0));
			if (hasHotelLightPurple2.boolValue() == true)
				p.buildHotel(p.getLightPurpleNameAt(1));
			else
				p.removeHotel(p.getLightPurpleNameAt(1));
			if (hasHotelLightPurple3.boolValue() == true)
				p.buildHotel(p.getLightPurpleNameAt(2));
			else
				p.removeHotel(p.getLightPurpleNameAt(2));
		}
		if (p.isOrangeComplete()) {
			p.buildHouse(
					p.getOrangeNameAt(0),
					NumHouseOrange1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getOrangeNameAt(0)));
			p.buildHouse(
					p.getOrangeNameAt(1),
					NumHouseOrange2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getOrangeNameAt(1)));
			p.buildHouse(
					p.getOrangeNameAt(2),
					NumHouseOrange3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getOrangeNameAt(2)));
			// build hotel
			if (hasHotelOrange1.boolValue() == true)
				p.buildHotel(p.getOrangeNameAt(0));
			else
				p.removeHotel(p.getOrangeNameAt(0));
			if (hasHotelOrange2.boolValue() == true)
				p.buildHotel(p.getOrangeNameAt(1));
			else
				p.removeHotel(p.getOrangeNameAt(1));
			if (hasHotelOrange3.boolValue() == true)
				p.buildHotel(p.getOrangeNameAt(2));
			else
				p.removeHotel(p.getOrangeNameAt(2));
		}
		if (p.isRedComplete()) {
			p.buildHouse(
					p.getRedNameAt(0),
					NumHouseRed1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getRedNameAt(0)));
			p.buildHouse(
					p.getRedNameAt(1),
					NumHouseRed2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getRedNameAt(1)));
			p.buildHouse(
					p.getRedNameAt(2),
					NumHouseRed3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getRedNameAt(2)));
			// build hotel
			if (hasHotelRed1.boolValue() == true)
				p.buildHotel(p.getRedNameAt(0));
			else
				p.removeHotel(p.getRedNameAt(0));
			if (hasHotelRed2.boolValue() == true)
				p.buildHotel(p.getRedNameAt(1));
			else
				p.removeHotel(p.getRedNameAt(1));
			if (hasHotelRed3.boolValue() == true)
				p.buildHotel(p.getRedNameAt(2));
			else
				p.removeHotel(p.getRedNameAt(2));
		}
		if (p.isYellowComplete()) {
			p.buildHouse(
					p.getYellowNameAt(0),
					NumHouseYellow1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getYellowNameAt(0)));
			p.buildHouse(
					p.getYellowNameAt(1),
					NumHouseYellow2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getYellowNameAt(1)));
			p.buildHouse(
					p.getYellowNameAt(2),
					NumHouseYellow3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getYellowNameAt(2)));
			// build hotel
			if (hasHotelYellow1.boolValue() == true)
				p.buildHotel(p.getYellowNameAt(0));
			else
				p.removeHotel(p.getYellowNameAt(0));
			if (hasHotelYellow2.boolValue() == true)
				p.buildHotel(p.getYellowNameAt(1));
			else
				p.removeHotel(p.getYellowNameAt(1));
			if (hasHotelYellow3.boolValue() == true)
				p.buildHotel(p.getYellowNameAt(2));
			else
				p.removeHotel(p.getYellowNameAt(2));
		}
		if (p.isGreenComplete()) {
			p.buildHouse(
					p.getGreenNameAt(0),
					NumHouseGreen1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getGreenNameAt(0)));
			p.buildHouse(
					p.getGreenNameAt(1),
					NumHouseGreen2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getGreenNameAt(1)));
			p.buildHouse(
					p.getGreenNameAt(2),
					NumHouseGreen3.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getGreenNameAt(2)));
			// build hotel
			if (hasHotelGreen1.boolValue() == true)
				p.buildHotel(p.getGreenNameAt(0));
			else
				p.removeHotel(p.getGreenNameAt(0));
			if (hasHotelGreen2.boolValue() == true)
				p.buildHotel(p.getGreenNameAt(1));
			else
				p.removeHotel(p.getGreenNameAt(1));
			if (hasHotelGreen3.boolValue() == true)
				p.buildHotel(p.getGreenNameAt(2));
			else
				p.removeHotel(p.getGreenNameAt(2));
		}
		if (p.isDarkBlueComplete()) {
			p.buildHouse(
					p.getDarkBlueNameAt(0),
					NumHouseDarkBlue1.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getDarkBlueNameAt(0)));
			p.buildHouse(
					p.getDarkBlueNameAt(1),
					NumHouseDarkBlue2.intValue()
							- this.currentPlayer
									.getNumberOfHouses(this.currentPlayer
											.getDarkBlueNameAt(1)));
			// build hotel
			if (hasHotelDarkBlue1.boolValue() == true)
				p.buildHotel(p.getDarkBlueNameAt(0));
			else
				p.removeHotel(p.getDarkBlueNameAt(0));
			if (hasHotelDarkBlue2.boolValue() == true)
				p.buildHotel(p.getDarkBlueNameAt(1));
			else
				p.removeHotel(p.getDarkBlueNameAt(1));
		}

	}

	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource() == doIt) {
			
			this.returnValue = 1;
			// update the cash and total wealth
			this.currentPlayer.subtractCash(this.totalCost.intValue());

			// build the houses and hotels
			updateBuildings(this.currentPlayer);

			// TESTPart
			System.out.println("cash after pressing doit: "
					+ this.currentPlayer.getCash());
			for (int i = 0; i < this.currentPlayer.getDarkPurpleSize(); i++) {
				String name = this.currentPlayer.getDarkPurpleNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getLightBlueSize(); i++) {
				String name = this.currentPlayer.getLightBlueNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getLightPurpleSize(); i++) {
				String name = this.currentPlayer.getLightPurpleNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getOrangeSize(); i++) {
				String name = this.currentPlayer.getOrangeNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getRedSize(); i++) {
				String name = this.currentPlayer.getRedNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getYellowSize(); i++) {
				String name = this.currentPlayer.getYellowNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getGreenSize(); i++) {
				String name = this.currentPlayer.getGreenNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			for (int i = 0; i < this.currentPlayer.getDarkBlueSize(); i++) {
				String name = this.currentPlayer.getDarkBlueNameAt(i);
				System.out.println(name + " has "
						+ this.currentPlayer.getNumberOfHouses(name));
				System.out.println(name + " has hotel?: "
						+ this.currentPlayer.hasHotel(name));
			}
			System.out.println("total Wealth after pressing DoIt is "
					+ this.currentPlayer.getTotalWealth());
			System.out.println("total houseNum after pressing DoIt is "
					+ this.currentPlayer.getTotalHouseNum());
			// TESTPart	
		}
		else if (e.getSource() == cancel){
			returnValue = 0;
		}
		
		
		setVisible(false);
		dispose();
	}

	public int getReturnValue() {
		return returnValue;
	}
	public void resetReturnValue(){
		returnValue = -1;
	}
	public boolean hasCompleteGroup(){
		if (currentPlayer.isDarkPurpleComplete() == false
				&& currentPlayer.isLightBlueComplete() == false
				&& currentPlayer.isLightPurpleComplete() == false
				&& currentPlayer.isOrangeComplete() == false
				&& currentPlayer.isRedComplete() == false
				&& currentPlayer.isYellowComplete() == false
				&& currentPlayer.isGreenComplete() == false
				&& currentPlayer.isDarkBlueComplete() == false)
			return false;
		return true;
	}
	public boolean canBuild(){
		int unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getDarkPurpleSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getDarkPurpleNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 2)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getLightBlueSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getLightBlueNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getLightPurpleSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getLightPurpleNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getOrangeSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getOrangeNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getRedSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getRedNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getYellowSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getYellowNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getGreenSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getGreenNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 3)
			return true;
		unmortgagedPropCounter = 0;
		for(int i = 0; i<currentPlayer.getDarkBlueSize() ; i++){
			if(currentPlayer.isMortgaged(currentPlayer.getDarkBlueNameAt(0)) == false)
				unmortgagedPropCounter++;
		}
		if(unmortgagedPropCounter == 2)
			return true;
		
		return false;
		
}
}
// TODO:make the number of buttons balanced
class ButtonsOfHouseHotel extends JPanel implements ActionListener {
	JLabel name;
	HouseButton h1, h2, h3, h4;
	HotelButton hotel;
	double cash; // player's cash
	int currentHouseNum;
	// int NumHouse1;
	// int NumHouse2;
	// int NumHouse3;
	int size;
	IntContainer totalCost;
	static double resultCash;
	IntContainer houseNum1, houseNum2, houseNum3;
	BooleanContainer hasHotel1, hasHotel2, hasHotel3;
	Player Player;
	String nameOfProperty;
	int minimumHouseNum;
	JLabel totalLabel;
	JLabel remainingCostLabel;
	int propertyNumber;// set to 0 if we're building on 1st house, 1 for second
	boolean hasHotel; // if it is true, we cannot anything on the land

	/*
	 * p -- Player colorNum -- # of the properties of the color(2 for
	 * darkpurple, 3 for red etc..) index -- if index is 0, HouseNum1 will be
	 * changed, totalCost -- of Type Double. its value can be changed from the
	 * every ButtonsOfHouseHotel objects str -- name of the property numHouse --
	 * starting # of houses of the property the value is the minimum number of
	 * houses. hasHotel -- return 1 if there is the hotel on the property
	 * "at first" HouseNum1, HouseNum2, HouseNum3 --
	 */

	ButtonsOfHouseHotel(Player p, int colorNum, int index,
			IntContainer totalCost, double cashResult, String str,
			int numHouse, boolean hasHotel, IntContainer HouseNum1,
			IntContainer HouseNum2, IntContainer HouseNum3,
			JLabel totalCostLabel, JLabel resultLabel,
			BooleanContainer hasHotel1, BooleanContainer hasHotel2,
			BooleanContainer hasHotel3) {

		// this.setBackground(Color.lightGray);
		size = colorNum;
		this.houseNum1 = HouseNum1;
		this.houseNum2 = HouseNum2;
		this.houseNum3 = HouseNum3;
		this.totalCost = totalCost;
		this.resultCash = cashResult;
		System.out.println(totalCost);
		this.Player = p;
		this.nameOfProperty = str;
		this.minimumHouseNum = numHouse;
		totalLabel = totalCostLabel;
		this.remainingCostLabel = resultLabel;
		propertyNumber = index;
		this.hasHotel1 = hasHotel1;
		this.hasHotel2 = hasHotel2;
		this.hasHotel3 = hasHotel3;
		this.hasHotel = hasHotel;

		// determining the currentHouseNum. if the index is 0. the
		// currentHouseNum is the first HouseNumber.
		// pressing the buttons here changes only the value of currentHouseNum
		// changing the value of currentHouseNum will change the value of
		// HouseNum1, HouseNum2, or HouseNum3.
		if (index == 0) {
			currentHouseNum = houseNum1.intValue();
		} else if (index == 1) {
			currentHouseNum = houseNum2.intValue();
		} else {
			currentHouseNum = houseNum3.intValue();
		}

		name = new JLabel(str);
		// name.setFont(new Font("SANS_SERIF", Font.BOLD, 16));

		// propertyButton = new JButton("PROPERTY");
		if (numHouse == 0) {
			h1 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h2 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		} else if (numHouse == 1) {
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		} else if (numHouse == 2) {
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		} else if (numHouse == 3) {
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		} else if (numHouse == 4 && hasHotel == false) {
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImage.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		} else if (numHouse == 4 && hasHotel == true) {
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImage.jpg");
			hotel = new HotelButton("./menuButtons/hotelImage.jpg");
		}

		// make buttons listen
		// propertyButton.addActionListener(this);
		h1.addActionListener(this);
		h2.addActionListener(this);
		h3.addActionListener(this);
		h4.addActionListener(this);
		hotel.addActionListener(this);

		// panel includes buttons
		add(name);
		// add(propertyButton);
		add(h1);
		add(h2);
		add(h3);
		add(h4);
		add(hotel);

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == h1) {// when pressing button h1
			// CASE1: There are 2 properties of the color
			if (size == 2) {
				if (this.propertyNumber == 0) {
					// we can't build the first building if there already exists
					// the house(can do only when currentHouseNum is 0).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 0
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {

						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						h1.changeImageToBuilt();// change the image to built

						this.houseNum1.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 1)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {

						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						h1.changeImageToSale();
						// update the houseNumber

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {

					// we can't build the first building if there already exists
					// the house(can do only when currentHouseNum is 0).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 0
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {

						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						h1.changeImageToBuilt();

						this.houseNum2.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 1)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {

						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						h1.changeImageToSale();
						// update the houseNumber

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
			// CASE2: There are 3 properties of the color
			else if (size == 3) {
				if (this.propertyNumber == 0) {

					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 0
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& //
							Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h1.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum1.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 1)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h1.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 0
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& //
							Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h1.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum2.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 1)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h1.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 2) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 0
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& //
							Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h1.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum3.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 1)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h1.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum3.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
		}

		if (e.getSource() == h2) {
			// CASE1: There are 2 properties of the color
			if (size == 2) {
				if (this.propertyNumber == 0) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h2.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum1.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 2)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h2.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h2.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum2.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 2)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h2.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
			// CASE2: There are 3 properties of the color
			else if (size == 3) {
				if (this.propertyNumber == 0) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h2.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 2)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h2.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h2.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 2)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h2.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 2) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h2.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 2)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h2.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
		}
		if (e.getSource() == h3) {
			// CASE1: There are 2 properties of the color
			if (size == 2) {
				if (this.propertyNumber == 0) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 2
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h3.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum1.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 3)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h3.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 2
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h3.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum2.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 3)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h3.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
			// CASE2: There are 3 properties of the color
			else if (size == 3) {
				if (this.propertyNumber == 0) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 2
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h3.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						if (this.propertyNumber == 0)
							this.houseNum1.increment();
						else if (this.propertyNumber == 1)
							this.houseNum2.increment();
						else
							this.houseNum3.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 3)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h3.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 2
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h3.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 3)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h3.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 2) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 2
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h3.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 3)
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h3.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
		}

		if (e.getSource() == h4) {
			// CASE1: There are 2 properties of the color
			if (size == 2) {
				if (this.propertyNumber == 0) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 3
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h4.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum1.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 4)
							&& this.hasHotel1.boolValue() == false
							&& this.hasHotel2.boolValue() == false
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h4.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// we can't build the first building if there already exists
					// 2 houses(can do only when currentHouseNum is 1).
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 3
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h4.changeImageToBuilt();
						this.currentHouseNum++;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						// update the houseNumber

						this.houseNum2.increment();
						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					// && it keeps the differece of houseNum <= 1
					// && the resulting currentHouseNum won't be less than the
					// minimum HouseNum
					else if ((currentHouseNum == 4)
							&& this.hasHotel1.boolValue() == false
							&& this.hasHotel2.boolValue() == false
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h4.changeImageToSale();
						this.currentHouseNum--;
						System.out.println(this.currentHouseNum);// test
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
			// CASE2: There are 3 properties of the color
			else if (size == 3) {
				if (this.propertyNumber == 0) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 3
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h4.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 4)
							&& this.hasHotel1.boolValue() == false
							&& this.hasHotel2.boolValue() == false
							&& this.hasHotel3.boolValue() == false
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h4.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum1.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 1) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 3
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum3
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h4.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 4)
							&& this.hasHotel1.boolValue() == false
							&& this.hasHotel2.boolValue() == false
							&& this.hasHotel3.boolValue() == false
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum3
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h4.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum2.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				} else if (this.propertyNumber == 2) {
					// if there is no house && the difference of these 2 houses
					// is less than 2, we can build
					// && the resulting cost doesnt exceed the player's cash
					if (currentHouseNum == 3
							&& Math.abs(((currentHouseNum + 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum + 1) - this.houseNum2
									.intValue())) <= 1
							&& this.Player.getCash() >= (this.totalCost
									.intValue() + this.Player
									.getBuildCost(this.nameOfProperty))) {
						h4.changeImageToBuilt();
						this.currentHouseNum++;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										+ this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash -= this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.increment();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
					// or we can deselect it when there is only one house on the
					// property.
					else if ((currentHouseNum == 4)
							&& this.hasHotel1.boolValue() == false
							&& this.hasHotel2.boolValue() == false
							&& this.hasHotel3.boolValue() == false
							&& Math.abs(((currentHouseNum - 1) - this.houseNum1
									.intValue())) <= 1
							&& Math.abs(((currentHouseNum - 1) - this.houseNum2
									.intValue())) <= 1
							&& currentHouseNum - 1 >= this.minimumHouseNum) {
						h4.changeImageToSale();
						this.currentHouseNum--;
						this.totalCost
								.setIntValue(this.totalCost.intValue()
										- this.Player
												.getBuildCost(this.nameOfProperty));
						this.resultCash += this.Player
								.getBuildCost(this.nameOfProperty);

						this.houseNum3.decrement();

						this.totalLabel.setText("Total cost: $"
								+ totalCost.intValue());
						this.remainingCostLabel.setText("Cash remaining: $"
								+ this.resultCash);
					}
				}
			}
		}
		if (e.getSource() == hotel) {
			if (this.hasHotel == false) {
				// CASE1: There are 2 properties of the color
				if (size == 2) {
					if (this.propertyNumber == 0) {
						// we can't build the first building if there already
						// exists 2 houses(can do only when currentHouseNum is
						// 1).
						// if there is no house && the difference of these 2
						// houses is less than 2, we can build
						// && the resulting cost doesnt exceed the player's cash
						if (this.hasHotel1.boolValue() == false
								&& this.houseNum1.intValue() == 4
								&& this.houseNum2.intValue() == 4
								&& this.Player.getCash() >= (this.totalCost
										.intValue() + this.Player
										.getBuildCost(this.nameOfProperty))) {
							hotel.changeImageToBuilt();
							// this.currentHouseNum++;
							// System.out.println(this.currentHouseNum);//test
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									+ this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash -= this.Player
									.getBuildCost(this.nameOfProperty);

							// update the houseNumber

							this.hasHotel1.setBoolValue(true);
							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ resultCash);
						}
						// or we can deselect it when there is only one house on
						// the property.
						// && it keeps the differece of houseNum <= 1
						// && the resulting currentHouseNum won't be less than
						// the minimum HouseNum
						else if (this.hasHotel1.boolValue() == true)
						// Math.abs(((currentHouseNum-1) -
						// this.houseNum2.intValue())) <= 1 &&)
						{
							hotel.changeImageToSale();
							// this.currentHouseNum--;
							System.out.println(this.currentHouseNum);// test
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									- this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash += this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel1.setBoolValue(false);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
					} else if (this.propertyNumber == 1) {
						// we can't build the first building if there already
						// exists 2 houses(can do only when currentHouseNum is
						// 1).
						// if there is no house && the difference of these 2
						// houses is less than 2, we can build
						// && the resulting cost doesnt exceed the player's cash
						if (this.hasHotel2.boolValue() == false
								&& this.houseNum1.intValue() == 4
								&& this.houseNum2.intValue() == 4
								&& this.Player.getCash() >= (this.totalCost
										.intValue() + this.Player
										.getBuildCost(this.nameOfProperty))) {
							hotel.changeImageToBuilt();
							// this.currentHouseNum++;
							System.out.println(this.currentHouseNum);// test
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									+ this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash -= this.Player
									.getBuildCost(this.nameOfProperty);

							// update the houseNumber

							this.hasHotel2.setBoolValue((true));

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ resultCash);
						}
						// or we can deselect it when there is only one house on
						// the property.
						// && it keeps the differece of houseNum <= 1
						// && the resulting currentHouseNum won't be less than
						// the minimum HouseNum
						else if (this.hasHotel2.boolValue() == true) {
							hotel.changeImageToSale();
							// this.currentHouseNum--;
							System.out.println(this.currentHouseNum);// test
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									- this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash += this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel2.setBoolValue(false);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
					}
				}
				// CASE2: There are 3 properties of the color
				else if (size == 3) {
					if (this.propertyNumber == 0) {
						// if there is no house && the difference of these 2
						// houses is less than 2, we can build
						// && the resulting cost doesnt exceed the player's cash
						if (this.hasHotel1.boolValue() == false
								&& this.houseNum1.intValue() == 4
								&& this.houseNum2.intValue() == 4
								&& this.houseNum3.intValue() == 4
								&& this.Player.getCash() >= (this.totalCost
										.intValue() + this.Player
										.getBuildCost(this.nameOfProperty))) {
							hotel.changeImageToBuilt();
							// this.currentHouseNum++;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									+ this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash -= this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel1.setBoolValue(true);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
						// or we can deselect it when there is only one house on
						// the property.
						else if (this.hasHotel1.boolValue() == true) {
							hotel.changeImageToSale();
							// this.currentHouseNum--;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									- this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash += this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel1.setBoolValue(false);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
					} else if (this.propertyNumber == 1) {
						// if there is no house && the difference of these 2
						// houses is less than 2, we can build
						// && the resulting cost doesnt exceed the player's cash
						if (this.hasHotel2.boolValue() == false
								&& this.houseNum1.intValue() == 4
								&& this.houseNum2.intValue() == 4
								&& this.houseNum3.intValue() == 4
								&& this.Player.getCash() >= (this.totalCost
										.intValue() + this.Player
										.getBuildCost(this.nameOfProperty))) {
							hotel.changeImageToBuilt();
							// this.currentHouseNum++;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									+ this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash -= this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel2.setBoolValue(true);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
						// or we can deselect it when there is only one house on
						// the property.
						else if (this.hasHotel2.boolValue() == true) {
							hotel.changeImageToSale();
							// this.currentHouseNum--;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									- this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash += this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel2.setBoolValue(false);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
					} else if (this.propertyNumber == 2) {
						// if there is no house && the difference of these 2
						// houses is less than 2, we can build
						// && the resulting cost doesnt exceed the player's cash
						if (this.hasHotel3.boolValue() == false
								&& this.houseNum1.intValue() == 4
								&& this.houseNum2.intValue() == 4
								&& this.houseNum3.intValue() == 4
								&& this.Player.getCash() >= (this.totalCost
										.intValue() + this.Player
										.getBuildCost(this.nameOfProperty))) {
							hotel.changeImageToBuilt();
							// this.currentHouseNum++;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									+ this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash -= this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel3.setBoolValue(true);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
						// or we can deselect it when there is only one house on
						// the property.
						else if (this.hasHotel3.boolValue() == true) {
							hotel.changeImageToSale();
							// this.currentHouseNum--;
							this.totalCost.setIntValue(this.totalCost
									.intValue()
									- this.Player
											.getBuildCost(this.nameOfProperty));
							this.resultCash += this.Player
									.getBuildCost(this.nameOfProperty);

							this.hasHotel3.setBoolValue(false);

							this.totalLabel.setText("Total cost: $"
									+ totalCost.intValue());
							this.remainingCostLabel.setText("Cash remaining: $"
									+ this.resultCash);
						}
					}
				}
			}
		}

	}
}

class DoubleContainer {
	private double doubleNum;

	public DoubleContainer(double num) {
		doubleNum = num;
	}

	public double doubleValue() {
		return doubleNum;
	}

	public void setDoubleValue(double value) {
		doubleNum = value;
	}
}

class IntContainer {
	private int intNum;

	public IntContainer(int num) {
		intNum = num;
	}

	public int intValue() {
		return intNum;
	}

	public void setIntValue(int num) {
		intNum = num;
	}

	public void increment() {
		intNum++;
	}

	public void decrement() {
		intNum--;
	}

}

class BooleanContainer {
	private boolean boolValue;

	public BooleanContainer(boolean boolValue) {
		this.boolValue = boolValue;
	}
	public BooleanContainer(){
		this.boolValue = false;
	}

	public boolean boolValue() {
		return boolValue;
	}

	public void setBoolValue(boolean boolVal) {
		boolValue = boolVal;
	}

}